import { fileURLToPath, URL } from "node:url";

import UnoCSS from "unocss/vite";
import { animatedUno } from "animated-unocss";
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import svgLoader from "vite-svg-loader";
import vueJsx from "@vitejs/plugin-vue-jsx";

import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import { NaiveUiResolver } from "unplugin-vue-components/resolvers";
import { ElementPlusResolver } from "unplugin-vue-components/resolvers";
const targetUrl = "http://aicim.com:7146";
export default defineConfig(({ mode }) => {
  return {
    base: "",
    esbuild: {
      drop: ["console", "debugger"],
    },
    plugins: [
      vue(),
      svgLoader(),
      UnoCSS(),
      animatedUno(),
      vueJsx(),
      AutoImport({
        resolvers: [ElementPlusResolver()],
        imports: [
          "vue",
          {
            "naive-ui": [
              "useDialog",
              "useMessage",
              "useNotification",
              "useLoadingBar",
            ],
          },
        ],
      }),
      Components({
        resolvers: [NaiveUiResolver(), ElementPlusResolver()],
      }),
    ],
    css: {
      preprocessorOptions: {
        scss: {
          api: "modern-compiler", // or 'modern'
        },
      },
    },
    resolve: {
      api: "modern-compiler", // or 'modern'
      alias: {
        "@": fileURLToPath(new URL("./src", import.meta.url)),
      },
    },
    server: {
      open: true,
      cors: true,
      port: 8090,
      host: "0.0.0.0",
      proxy: {
        "/vy": {
          changeOrigin: true,
          target: targetUrl,
        },
        "/vy/omREST": {
          changeOrigin: true,
          target: "http://aicim.com:7146",
        },
        "/storage": {
          changeOrigin: true,
          target: "https://es-flight-api-cn.djigate.com",
        },
        "/task": {
          target: "https://es-flight-api-cn.djigate.com",
          changeOrigin: true,
        },
      },
    },
  };
});
